/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.model.service;

import com.model.domain.tiempo.Actividad;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;


/**
 *
 * @author Rdelacruz
 */
public class ActividadService 
extends AbstractService
{

    private void setear(ResultSet rs, Actividad obj) throws SQLException {
        obj.setCodigo(rs.getString("CodActividad"));
        obj.setNombre(rs.getString("DesActividad"));
        obj.setAsignable(rs.getBoolean("asignable"));
    }
    
    public List<Actividad> findAll(Connection con) throws SQLException {
        List<Actividad> lista = new ArrayList<Actividad>();
        Statement st = null;
        try {                        
            st = con.createStatement();
            String sql = "select * from Campo_Actividad";
            ResultSet rs = st.executeQuery(sql);            
            while(rs.next()) {
                Actividad obj = new Actividad();
                setear(rs,obj);
                lista.add(obj);
            }
        }
        finally {
            if(st!=null) st.close();
        }
        return lista;
    }

    public Actividad findByCodigo(Connection con, String codigo) throws SQLException {
        Statement st = null;
        try {                        
            st = con.createStatement();
            String sql = "select * from Campo_Actividad where CodActividad='"+codigo+"'";
            ResultSet rs = st.executeQuery(sql);            
            if(rs.next()) {
                Actividad obj = new Actividad();
                setear(rs,obj);
                return obj;
            }
        }
        finally {
            if(st!=null) st.close();
        }
        return null;
    }

    
    
}
